package lt.mockos.app.client.cpu.hw;

public class Converter {

    public static int stringToInt(String word) {
        int result;
        if (word.matches("^[0-9]+$")) {
            result = Integer.valueOf(word);

        } else {
            char[] w = word.toCharArray();
            result = w[0] * 255 * 255 * 255 + w[1] * 255 * 255 + w[2] * 255 + w[3];
        }
        return result;
    }

    public static String intToString(int word) {
        String result;
        if (word > 9999) {
            char a = (char) (word % 255);
            word /= 255;
            char b = (char) (word % 255);
            word /= 255;
            char c = (char) (word % 255);
            word /= 255;
            char d = (char) (word % 255);
            word /= 255;
            char[] reversed = { d, c, b, a };
            result = String.valueOf(reversed);
        } else {
            result = String.valueOf(word);
        }
        return result;

    }
}
